package com.tjec.project.projectWorkbench.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.tjec.common.utils.SecurityUtils;
import com.tjec.common.utils.StringUtils;
import com.tjec.project.projectWorkbench.domain.BmsProjectSimple;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.project.projectWorkbench.domain.BmsProjectFocus;
import com.tjec.project.projectWorkbench.service.IBmsProjectFocusService;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.web.page.TableDataInfo;

/**
 * 关注的项目 Controller
 * 
 * @author cjj
 * @date 2020-05-25
 */
@Api(value = "关注的项目", tags = {"关注的项目接口"})
@RestController
@RequestMapping("/project/focus")
public class BmsProjectFocusController extends BaseController
{
    @Autowired
    private IBmsProjectFocusService bmsProjectFocusService;

    /**
     * 关注或取消关注项目
     */
    @ApiOperation("关注或取消关注项目")
    @Log(title = "关注的项目 ", businessType = BusinessType.INSERT)
//    @PreAuthorize("@ss.hasPermi('project:focus:addOrEdit')")
    @PostMapping
    public AjaxResult add(BmsProjectFocus bmsProjectFocus)
    {
        bmsProjectFocus.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        Set<BmsProjectFocus> list = bmsProjectFocusService.selectBmsProjectFocusList(bmsProjectFocus);
        if(!CollectionUtils.isEmpty(list)){
            int i = 0 ;
            for (BmsProjectFocus focus : list) {
                i = bmsProjectFocusService.deleteBmsProjectFocusByGuid(focus.getGuid());
                if(i==0){
                    break;
                }
            }
            return toAjax(i);
        }else{
            return toAjax(bmsProjectFocusService.insertBmsProjectFocus(bmsProjectFocus));
        }
    }
}
